// 管理extension.list标签
var managerTag = Vue.component('managerTag', {
    template: readComponentHTML("managerTag"),
    data() {
        return {
            config: {
                userName: "",
                passWord: "",
                repositoryList: []
            },
            tagList:[],
            update: {
                branch: "hotfix/xxxx",
                tag: "TAGV2.5.1-xxxx"
            },
            data:[],
            showTagList: false,
            rules: {
                gitUrl: [
                    {required: true, message: '请输入仓库地址', trigger: 'blur'},
                ],
                branch: [
                    {required: true, message: '请输入仓库分支', trigger: 'blur'}
                ]
            }
        };
    },
    mounted() {
        this.init();
    },
    methods: {
        // 初始化 读取全局的标签集合
        init: function () {
            var that = this;
            that.openLoading();
            axios.get('/version/controll/config/load')
                .then(function (response) {
                    if (response.data) {
                        that.config = response.data;
                    }
                    that.closeLoading();
                });
        },
        createTag: function (inde, data) {
            var that = this;
            that.openLoading();
            var tagDto = {
                projectName : data.name,
                branch: this.update.branch,
                tagName: this.update.tag
            }
            axios
                .post('/version/controll/tag/create',
                    JSON.stringify(tagDto),
                    {headers: {'Content-Type': 'application/json'}})
                .then(function (response) {
                    that.closeLoading();
                })
                .catch(error => this.$message.error(JSON.stringify(error)));
        },
        getTagList: function (inde, data) {
            this.getTagListFunc(data.name);
        },
        getTagListFunc: function(name) {
            var that = this;
            that.openLoading();
            axios.get('/version/controll/tag/list/' + name)
                .then(function (response) {
                    that.showTagList = true;
                    that.tagList = [];
                    if (response.data) {
                        response.data.forEach(function(tag){
                            that.tagList.push({
                                name: tag,
                                projectName: name
                            })
                        })
                    }
                    that.closeLoading();
                });
        },
        delTag: function (inde, data) {
            var that = this;
            that.openLoading();
            axios.get('/version/controll/tag/del/' + data.projectName + '/' + data.name)
                .then(function (response) {
                    that.getTagListFunc(data.projectName);
                    that.closeLoading();
                });
        },
        batchCreateTag: function () {

        }
    }
})